package hu.tortavar2.server;

import java.util.List;

import hu.tortavar2.client.SiteService;
import hu.tortavar2.shared.Product;
import hu.tortavar2.shared.ProductCategory;
import hu.tortavar2.shared.Shop;

import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class SiteServiceImpl extends RemoteServiceServlet implements SiteService {

	@Override
	public String getBlobStoreUploadUrl() {
		BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
		return blobstoreService.createUploadUrl("/upload");
	}

	@Override
	public List<ProductCategory> getProductCategory() {
		// TODO Auto-generated method stub
		ProductCategoryDao dao = new ProductCategoryDao();
		
		return dao.getRecentCategory();
	}

	public void addNewCategory(ProductCategory category) {
		// TODO Auto-generated method stub
		ProductCategoryDao dao = new ProductCategoryDao();
		dao.addProductCategory(category);
	}

	public void deleteCategory(String encodedKey) {
		// TODO Ellenőrizni, hogy érvényes kulcsot adott-e meg...
		ProductCategoryDao dao = new ProductCategoryDao();
		dao.deleteCategory(encodedKey);
	}

	@Override
	public List<Shop> getShops() {
		ShopDao dao = new ShopDao();
		return dao.getRecentShops();
	}

	public void addShop(Shop shop) {
		// TODO Auto-generated method stub
		ShopDao dao = new ShopDao();
		dao.AddShop(shop);
	}

	@Override
	public void deleteShop(String encodedKey) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Product> getProducts(String category) {
		ProductDao dao = new ProductDao();
		return dao.getRecentProducts(category);
	}

	@Override
	public Product getProduct(String encodedKey) {
		ProductDao dao = new ProductDao();
		return dao.getProductByKey(encodedKey);
	}

}
